package com.Dlg 
{
	import com.data.GameData;
	import com.event.EventManager;
	import com.event.PublicEvent;
	import components.Button;
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.utils.setTimeout;
	
	/**
	 * 结束弹框
	 * @author wen
	 */
	public class EndDlg extends BasicDlg 
	{
		private var _data:Object = null;
		
		private var _label:TextField = null;
		
		private var _btn0:Button = null;
		
		private var _btn1:Button = null;
		
		public function EndDlg() 
		{
			
		}
		
		/**
		 * 显示
		 * @param	obj
		 */
		public function show(obj:Object=null):void 
		{
			_data = obj;
			if (!isInit)
			{
				var tmpMc:MovieClip = new scoreDlg();
				setTimeout(init,10,tmpMc,initDlg);
				isInit = true;
				return;
			}
			
			_label.text = _data.score;
			
			
			showDlg();
		}
		
		private function initDlg():void 
		{
			_label = view.label;
			_label.text = "";
			
			_btn0 = new Button(view.btn0);
			_btn0.label = "Restart";
			_btn0.addEventListener(MouseEvent.CLICK, onBtn0ClickHander);
			
			_btn1 = new Button(view.btn1);
			_btn1.label = "Back";
			_btn1.addEventListener(MouseEvent.CLICK, onBtn1ClickHander);
			
			view.x = GameData.gameWidth/2;
			view.y = GameData.gameHeigth/2-50;
			
			show(_data);
		}
		
		private function onBtn1ClickHander(e:MouseEvent):void 
		{	
			EventManager.instance.dispatchEvent(new PublicEvent(PublicEvent.BACK));
			hide();
		}
		
		private function onBtn0ClickHander(e:MouseEvent):void 
		{
			EventManager.instance.dispatchEvent(new PublicEvent(PublicEvent.RESTART));
			GameData.isStart = true;
			hide();
		}
		
		
		private function clear():void 
		{
			_label.text = "";
		}
		
		
	}

}